﻿
$(function() {
    JSUtility.url = '../Handler/AjaxHandle.ashx';
    JSUtility.param = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.EducationPresenter", Method: "Search", Options: {} };
    autoResize({ dataGrid: '#Grid', callback: InitWorkEducationlist });
    $('#btnSubmit,#btnCancel').linkbutton();

    JSUtility.window_edit_form = $("#WorkEducationfrm");
    JSUtility.window_edit = $("#WorkEducationWin");
    $("#btnAdd").bind("click", function() {
        JSUtility.param.Options["EducationType"] = "1";
        JSUtility.add();
    });
    $("#btnDel").click(JSUtility.del);
    $("#btnEdit").bind("click", function() {
        var rows = $("#Grid").datagrid('getSelections');
        var num = rows.length;
        if (num == 0) {
            $.messager.alert('提示', '请选择一条记录进行操作!', 'info');
            return;
        }
        else {
            JSUtility.param.Options["EducationType"] = "1";
            $("#IsSignProtocol").prop("checked", rows[0].IsSignProtocol);
        }
        JSUtility.update();
    });
    $("#btnRefersh").click(function() {
        $('#Grid').datagrid('reload');
    });
    $("#btnAddPerson").click(function() {
        var rows = $("#Grid").datagrid('getSelections');
        var num = rows.length;
        if (num == 0) {
            $.messager.alert('提示', '请选择一条记录进行操作!', 'info');
            return;
        } else {
            self.parent.addTab("在职教育员工信息", "../Personnel/EducationPerson.htm?Id=" + rows[0].Id, "icon-sys");
        }
    });
    $("#btnSubmit").click(function() {
        JSUtility.param.Options["IsSignProtocol"] = $("#IsSignProtocol").prop("checked");
        JSUtility.param.Options["TrainingInstitutions"] = $("#TrainingInstitutions").combobox("getText");

        JSUtility.save();
    });
    $('#btnCancel').click(JSUtility.close);
    $("#TrainingInstitutions").combobox({
        valueField: 'id',
        textField: 'text',
        editable: true,
        data: [{
            "id": 0,
            "text": "设计院公司",
            "selected": "true"
        }, {
            "id": 1,
            "text": "通号集团内其他单位"
        }, {
            "id": 2,
            "text": "自费"
        }, {
            "id": 3,
            "text": "其他"
}]
        });
    });

    function InitWorkEducationlist(size) {
        JSUtility.param.Options["EducationType"] = "1";
        var p = JSUtility.param;
        JSUtility.grid = $('#Grid').datagrid({
            width: size.width,
            height: size.height,
            pageSize: Math.round(size.height / 25),
            pageList: [Math.round(size.height / 25)],
            striped: true,
            queryParams: { "json": $.toJSON(p) },
            url: JSUtility.url,
            singleselect: true
        });
    }


    function IsSignProtocolFormatter(value) {
        if (value == "True") {
            return "签订服务协议";
        } else {
            return "未签订服务协议";
        }
    }
